﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
 
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class titleSubTitle : DemoBaseUserControl
    {
        public titleSubTitle()
        {
            InitializeComponent();
            this.Title = "标题和子标题";
            this.Description = "Spread .NET  可以在 SpreadSheet 的顶部添加一个特殊格式化的区域，这个区域用来显示标题和子标题。";
        }

        private void titleSubTitle_Load(object sender, EventArgs e)
        {
            this.FpSpread1.DataSource = this.销售明细表TableAdapter.GetData();
            FpSpread1.TitleInfo.Height = 40;
            FpSpread1.TitleInfo.Visible = true;
            FpSpread1.TitleInfo.BackColor = Color.LightBlue;
            FpSpread1.TitleInfo.ForeColor = Color.DarkGreen;
            FpSpread1.TitleInfo.Text = "这是Spread的标题";
            FpSpread1.Sheets[0].TitleInfo.Visible = true;
            FpSpread1.Sheets[0].TitleInfo.Height = 40;
            FpSpread1.Sheets[0].TitleInfo.Text = "这是Spread Win version 5的新功能";
            FpSpread1.Sheets[0].TitleInfo.BackColor = Color.Salmon;
            FpSpread1.Sheets[0].TitleInfo.ForeColor = Color.Yellow;

            ckSpreadVisible.Checked = FpSpread1.TitleInfo.Visible;
            nrTitleHeight.Value = FpSpread1.TitleInfo.Height;
            txtSpreadTitle.Text = FpSpread1.TitleInfo.Text;

            ckSheetTitle.Checked = FpSpread1.ActiveSheet.TitleInfo.Visible;
            nrSheetTitleHeight.Value = FpSpread1.ActiveSheet.TitleInfo.Height;
            txtSheetTitle.Text = FpSpread1.ActiveSheet.TitleInfo.Text;

            txtSheetTitle.KeyUp += new KeyEventHandler(txtSheetTitle_KeyUp);
            txtSpreadTitle.KeyUp += new KeyEventHandler(txtSpreadTitle_KeyUp);
            txtSpreadTitle.Leave += new EventHandler(txtSpreadTitle_Leave);
            txtSheetTitle.Leave += new EventHandler(txtSheetTitle_Leave);
        }

        void txtSheetTitle_Leave(object sender, EventArgs e)
        {
            if (txtSheetTitle.Text != null)
            {
                FpSpread1.ActiveSheet.TitleInfo.Text = txtSheetTitle.Text;
            }
        }

        void txtSpreadTitle_Leave(object sender, EventArgs e)
        {
            if (txtSpreadTitle.Text != null)
            {
                FpSpread1.TitleInfo.Text = txtSpreadTitle.Text;
            }
        }

        void txtSpreadTitle_KeyUp(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Enter) & (txtSpreadTitle.Text != null))
            {
                FpSpread1.TitleInfo.Text = txtSpreadTitle.Text;
            }
        }

        void txtSheetTitle_KeyUp(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Enter) & (txtSheetTitle.Text != null))
            {
                FpSpread1.ActiveSheet.TitleInfo.Text = txtSheetTitle.Text;
            }
        }

        private void ckSpreadVisible_CheckedChanged(object sender, EventArgs e)
        {
            FpSpread1.TitleInfo.Visible = ckSpreadVisible.Checked;
        }

        private void ckSheetTitle_CheckedChanged(object sender, EventArgs e)
        {
            FpSpread1.ActiveSheet.TitleInfo.Visible = ckSheetTitle.Checked;
        }

        private void nrTitleHeight_ValueChanged(object sender, EventArgs e)
        {
            FpSpread1.TitleInfo.Height = Convert.ToInt16(nrTitleHeight.Value);
        }

        private void nrSheetTitleHeight_ValueChanged(object sender, EventArgs e)
        {
            FpSpread1.ActiveSheet.TitleInfo.Height = Convert.ToInt16(nrSheetTitleHeight.Value);
        }

        private void btnBackColor_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = FpSpread1.TitleInfo.BackColor;
            colorDialog1.ShowDialog();
            if (!colorDialog1.Color.Equals(FpSpread1.TitleInfo.BackColor))
            {
                FpSpread1.TitleInfo.BackColor = colorDialog1.Color;
                FpSpread1.Refresh();
            }
        }

        private void btnSheetTitleBackColor_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = FpSpread1.ActiveSheet.TitleInfo.BackColor;
            colorDialog1.ShowDialog();
            if (!colorDialog1.Color.Equals(FpSpread1.ActiveSheet.TitleInfo.BackColor))
            {
                FpSpread1.ActiveSheet.TitleInfo.BackColor = colorDialog1.Color;
                FpSpread1.Refresh();
            }
        }

        private void btnForeColor_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = FpSpread1.TitleInfo.ForeColor;
            colorDialog1.ShowDialog();
            if (!colorDialog1.Color.Equals(FpSpread1.TitleInfo.ForeColor))
            {
                FpSpread1.TitleInfo.ForeColor = colorDialog1.Color;
                FpSpread1.Refresh();
            }
        }

        private void btnSheetTitleForeColor_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = FpSpread1.ActiveSheet.TitleInfo.ForeColor;
            colorDialog1.ShowDialog();
            if (!colorDialog1.Color.Equals(FpSpread1.ActiveSheet.TitleInfo.ForeColor))
            {
                FpSpread1.ActiveSheet.TitleInfo.ForeColor = colorDialog1.Color;
                FpSpread1.Refresh();
            }
        }

        private void cboVertical_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cboVertical.SelectedItem.ToString())
            {
                case "Top":
                    FpSpread1.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Top;
                    break;
                case "Center":
                    FpSpread1.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Center;
                    break;
                case "Bottom":
                    FpSpread1.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Bottom;
                    break;
                case "General":
                    FpSpread1.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.General;
                    break;
                case "Justify":
                    FpSpread1.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Justify;
                    break;
                case "Distributed":
                    FpSpread1.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Distributed;
                    break;
                default:
                    return;
            }
        }

        private void cbSheetTitleVertical_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cbSheetTitleVertical.SelectedItem.ToString())
            {
                case "Top":
                    FpSpread1.ActiveSheet.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Top;
                    break;
                case "Center":
                    FpSpread1.ActiveSheet.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Center;
                    break;
                case "Bottom":
                    FpSpread1.ActiveSheet.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Bottom;
                    break;
                case "General":
                    FpSpread1.ActiveSheet.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.General;
                    break;
                case "Justify":
                    FpSpread1.ActiveSheet.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Justify;
                    break;
                case "Distributed":
                    FpSpread1.ActiveSheet.TitleInfo.VerticalAlign = FarPoint.Win.Spread.CellVerticalAlignment.Distributed;
                    break;
                default:
                    return;
            }
        }

        private void cboHorizontal_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cboHorizontal.SelectedItem.ToString())
            {
                case "Left":
                    FpSpread1.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Left;
                    break;
                case "Center":
                    FpSpread1.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
                    break;
                case "Right":
                    FpSpread1.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Right;
                    break;
                case "General":
                    FpSpread1.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.General;
                    break;
                case "Justify":
                    FpSpread1.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Justify;
                    break;
                case "Distributed":
                    FpSpread1.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Distributed;
                    break;
                default:
                    return;
            }
        }

        private void cbSheetTitleHorizontal_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cbSheetTitleHorizontal.SelectedItem.ToString())
            {
                case "Left":
                    FpSpread1.ActiveSheet.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Left;
                    break;
                case "Center":
                    FpSpread1.ActiveSheet.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
                    break;
                case "Right":
                    FpSpread1.ActiveSheet.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Right;
                    break;
                case "General":
                    FpSpread1.ActiveSheet.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.General;
                    break;
                case "Justify":
                    FpSpread1.ActiveSheet.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Justify;
                    break;
                case "Distributed":
                    FpSpread1.ActiveSheet.TitleInfo.HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Distributed;
                    break;
                default:
                    return;
            }
        }
    }
}
